﻿using System;
using System.Diagnostics.Contracts;

namespace BlindData
{
	public struct Probability : IEquatable<Probability>, IComparable<Probability>
	{
		private double _value;

		public Probability(double value)
			: this()
		{
			Contract.Requires(value >=0 && value <= 1);

			_value = value;

		}

		public double ToDouble()
		{
			return _value;
		}

		public override bool Equals(object obj)
		{
			return obj is Probability && Equals((Probability)obj);
		}

		public override int GetHashCode()
		{
			return _value.GetHashCode();
		}


		#region IEquatable<Probability> Members

		public bool Equals(Probability other)
		{
			return _value.Equals(other._value);
		}

		#endregion

		#region IComparable<Probability> Members

		public int CompareTo(Probability other)
		{
			return _value.CompareTo(other._value);
		}

		#endregion

		public static implicit operator double(Probability probability)
		{
			return probability._value;
		}


		public static implicit operator Probability(double value)
		{
			return new Probability(value);
		}


		public static bool operator ==(Probability x, Probability y)
		{
			return x.Equals(y);
		}

		public static bool operator !=(Probability x, Probability y)
		{
			return !(x == y);
		}

		public static bool operator >(Probability x, Probability y)
		{
			return x.CompareTo(y) > 0;
		}

		public static bool operator <(Probability x, Probability y)
		{
			return x.CompareTo(y) < 0;
		}

		public static bool operator >=(Probability x, Probability y)
		{
			return x.CompareTo(y) >= 0;
		}

		public static bool operator <=(Probability x, Probability y)
		{
			return x.CompareTo(y) <= 0;
		}

	}

}
